package basic

/**
 * null安全
 *
 *
 */
fun main(args: Array<String>) {
    var str = "fkit"

    //由于字符串转Int可能会失败，当转换失败时，str.toIntOrNull()将返回null
    //前面提到过Int不能接收null,因此下面代码会编译异常
    // var num1: Int = str.toIntOrNull()
    //应该使用Int?
    var num2: Int? = str.toIntOrNull()

    println(num2)

    var b: String? = "bbbb"
    println(b?.length)
    b = null
    println(b?.length)


    val array: Array<String?> = arrayOf("aaa", "bbb", null, "ddd")
    for (item in array) {
        item?.let { println(it) }
    }


}